<template>
	<form-container title="编辑" :width="700" :visible="visible" :destroy-on-close="true" @close="onClose">
		<a-form ref="formRef" :model="formState" :rules="rules" layout="vertical">
			<!-- <a-descriptions-item label="编号">{{ formState.id }}</a-descriptions-item> -->
			<a-form-item label="单号：" name="comenumber">
				<a-input v-model:value="formState.comenumber" placeholder="请输入单号" allow-clear />
			</a-form-item>
			<a-form-item label="物料总数：" name="total">
				<a-input v-model:value="formState.total" placeholder="物料总数" allow-clear />
			</a-form-item>
			<a-form-item label="检验方案" name="scheme">
				<a-input v-model:value="formState.scheme" placeholder="检验方案" allow-clear />
			</a-form-item>
			<a-form-item label="状态：" name="state">
				<a-radio-group
					v-model:value="formState.state"
					placeholder="请选择状态"
					:options="processModeOptions"
				></a-radio-group>
			</a-form-item>
			<a-form-item label="结果：" name="outcome">
				<a-input v-model:value="formState.outcome" placeholder="请输入结果" allow-clear />
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
		</template>
	</form-container>
</template>

<script setup name="updatePassword">
	import { required } from '@/utils/formRules'
	import processApi from '@/api/mes/quality/incomingApi'
	import tool from '@/utils/tool'

	// 定义emit事件
	const emit = defineEmits({ successful: null })
	// 默认是关闭状态
	let visible = ref(false)
	const formRef = ref()
	// 表单数据
	const formState = ref({})
	const submitLoading = ref(false)

	// 打开抽屉
	const onOpen = (email) => {
		visible.value = true
		formState.value = email
	}
	// 关闭抽屉
	const onClose = () => {
		emit('successful')
		visible.value = false
	}
	// 默认要校验的
	const rules = {
		name: [required('请输入名称')]
	}

	// 提交数据
	const onSubmit = async () => {
		formRef.value.validateFields().then(() => {
			submitLoading.value = true
			let fromData = {
				id: formState.value.id,
				comenumber: formState.value.comenumber,
				state: formState.value.state,
				scheme: formState.value.scheme,
				total: formState.value.total,
				outcome: formState.value.outcome
			}
			// 提交数据
			processApi
				.processUpdate(fromData)
				.then(() => {
					//formRef.value.resetFields()
					visible.value = false
					emit('successful', fromData)
				})
				.finally(() => {
					submitLoading.value = false
					callback() //调用组件中的回调方法
				})
		})
	}

	//类型
	const processTypeOptions = tool.dictList('PROCESS_TYPE')
	// 报工模式
	//const processModeOptions = tool.dictList('PROCESS_MODE')
	// 状态
	const processModeOptions = tool.dictList('lailiaoType')

	// 调用这个函数将子组件的一些数据和方法暴露出去
	defineExpose({
		onOpen
	})
</script>

<style scoped></style>
